package com.zhiwen.design.factory.complex;

import com.zhiwen.design.factory.Add;
import com.zhiwen.design.factory.Arithmetic;

/**
 * @Auther: wuzhiwen
 * @Date: 2018/12/4 10:33
 * @Description:
 */
public class TestFactory {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        //反射获取
        ComplexFactory add = (ComplexFactory) Class.forName("com.zhiwen.design.factory.complex.AddFactory").newInstance();
        ComplexFactory del = (ComplexFactory) Class.forName("com.zhiwen.design.factory.complex.DeleteFactory").newInstance();
        ComplexFactory div = (ComplexFactory) Class.forName("com.zhiwen.design.factory.complex.DivideFactory").newInstance();
        ComplexFactory mul = (ComplexFactory) Class.forName("com.zhiwen.design.factory.complex.MultiplyFactory").newInstance();
        //工厂创建对象
        Arithmetic arithmeticAdd = add.getArithmetic();
        Arithmetic arithmeticDel = del.getArithmetic();
        Arithmetic arithmeticDiv = div.getArithmetic();
        Arithmetic arithmeticMul = mul.getArithmetic();
        //打印结果
        System.out.println(arithmeticAdd.setNumber(1,2));
        System.out.println(arithmeticDel.setNumber(1,2));
        System.out.println(arithmeticDiv.setNumber(1,2));
        System.out.println(arithmeticMul.setNumber(1,2));

    }
}
